using System;

namespace BSDS.Core.Data.Local.Csv.Parsing
{
    public class CsvType
    {
        public static CsvType Comma = new CsvType("csv", CsvSeparator.Comma);
        public static CsvType Tab = new CsvType("tab", CsvSeparator.Tab);
        public static CsvType Pipe = new CsvType("txt", CsvSeparator.Pipe);

        public string Value { get; private set; }
        public CsvSeparator Separator { get; private set; }

        public CsvType(string value, CsvSeparator separator)
        {
            Value = value;
            Separator = separator;
        }

        public static CsvType Parse(string value)
        {
            if (value == Comma.Value)
            {
                return Comma;
            }
            if (value == Tab.Value)
            {
                return Tab;
            }
            if (value == Pipe.Value || value == "pipe") // check "pipe" for backward compatibility
            {
                return Pipe;
            }

            throw new ArgumentOutOfRangeException(value);
        }
    }
}